home *** CD-ROM | disk | FTP | other *** search
/ Chip 2006 June / CHIP 2006-06.2.iso / program / freeware / Democracy-0.8.2.exe / components / mycontentpolicy.py < prev    next >
Encoding:
Python Source  |  2006-04-10  |  1.7 KB  |  39 lines

  1. from xpcom import components
  2. import traceback
  3. import sys
  4. import config
  5. import webbrowser
  6.  
  7. class MyContentPolicy:
  8.     _com_interfaces_ = [components.interfaces.nsIContentPolicy]
  9.     _reg_clsid_ = "{CFECB6A2-24AE-48f4-9A7A-87E62B972795}"
  10.     _reg_contractid_ = "@participatoryculture.org/dtv/mycontentpolicy;1"
  11.     _reg_desc_ = "Democracy content policy"
  12.  
  13.     def __init__(self):
  14.         pass
  15.  
  16.     def shouldLoad(self, contentType, contentLocation, requestOrigin, context, mimeTypeGuess,  extra):
  17.         url = contentLocation.spec
  18.         if ((contentType != components.interfaces.nsIContentPolicy.TYPE_DOCUMENT) or
  19.             (url.startswith('chrome:') or
  20.             url.startswith('http://127.0.0.1:') or  # FIXME get server port
  21.             url.startswith('resource:') or
  22.             url.startswith('about:') or
  23.             url.startswith('javascript:') or
  24.             url.startswith(config.get(config.CHANNEL_GUIDE_URL)))):
  25.             return components.interfaces.nsIContentPolicy.ACCEPT
  26.         else:
  27.             print "DTV: openning %s in new window" % url
  28.             # FIXME: Should this use the same code as UIBackendDelegate?
  29.             webbrowser.open(contentLocation.spec)
  30.             return components.interfaces.nsIContentPolicy.REJECT_SERVER
  31.  
  32.     def shouldProcess(self, contentType, contentLocation, requestOrigin, context, mimeType,  extra):
  33.         return components.interfaces.nsIContentPolicy.ACCEPT
  34.  
  35. catman = components.classes["@mozilla.org/categorymanager;1"].getService()
  36. catman.queryInterface(components.interfaces.nsICategoryManager)
  37. catman.addCategoryEntry("content-policy", "@participatoryculture.org/dtv/mycontentpolicy;1", "@participatoryculture.org/dtv/mycontentpolicy;1", True, True)
  38.  
  39.